package cn.wolfcode.trip.app.controller;

import cn.wolfcode.trip.base.domain.Follow;
import cn.wolfcode.trip.base.service.IFollowService;
import cn.wolfcode.trip.base.util.JSONResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by 24106 on 2018/8/30.
 */
@RestController
@RequestMapping("follows")
public class FollowController {
    @Autowired
    private IFollowService followService;
    //查询是否当前用户与当前页面用户是否存在对应的关系2019/6/16第一次测试
    @RequestMapping("getRelation")
    public Follow getRelation(Follow follow){
        return followService.getRelation(follow);
    }

    /**
     * 关注
     * @param follow
     * @return
     */
    @RequestMapping(value = "/save",method = RequestMethod.PUT)
    public JSONResult save(Follow follow){
        JSONResult result = new JSONResult();
        try{
            followService.save(follow);
        }catch (Exception e){
            e.printStackTrace();
            result.mark(e.getMessage());
        }
        return result;
    }

    /**
     * 取消关注
     */
    @RequestMapping(value = "/{fanId}/{followId}",method = RequestMethod.DELETE)
    public JSONResult delete(@PathVariable("fanId") Long fanId, @PathVariable("followId") Long followId){
        System.out.println(fanId);
        System.out.println(followId);
        JSONResult result = new JSONResult();
        try{
            followService.delete(fanId,followId);
        }catch (Exception e){
            e.printStackTrace();
            result.mark(e.getMessage());
        }
        return result;
    }
}
